﻿@using YunSpace.Core
@{
    ViewBag.Title = "Info";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    $(function () {
        $('.wrapper').height($(window).height() - 11);
    })
</script>

<style>
    .ui-jqgrid .ui-jqgrid-hbox {
        padding-right: 0;
    }
</style>

<div class="wrapper">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#a" data-toggle="tab">基本信息</a></li>
        <li><a href="#b" data-toggle="tab">注册信息</a></li>
        <li><a href="#c" data-toggle="tab">系统日志</a></li>
    </ul>
    <div class="tab-content" style="padding-top: 5px;">

        <div id="a" class="tab-pane active" style="padding: 15px;">

            <ul class="pop-list">
                <li>
                    <label>账户</label>
                    <input id="F_Account" name="F_Account" type="text" class="form-control" />
                </li>
                <li>
                    <label>姓名</label>
                    <input type="text" id="F_RealName" name="F_RealName" class="form-control" />
                </li>
                <li>
                    <label>性别</label>
                    <input id="F_Gender" name="F_Gender" type="text" class="form-control" />
                </li>
                <li>
                    <label>出生</label>
                    <input id="F_Birthday" name="F_Birthday" type="text" class="form-control" />
                </li>
                <li>
                    <label>公司</label>
                    <input id="F_Organize" name="F_Organize" type="text" class="form-control" />
                </li>
                <li>
                    <label>部门</label>
                    <input id="F_Department" name="F_Department" type="text" class="form-control" />
                </li>
                <li>
                    <label>角色</label>
                    <input id="F_Role" name="F_Role" type="text" class="form-control" />
                </li>
                <li>
                    <label>岗位</label>
                    <input id="F_Duty" name="F_Duty" type="text" class="form-control" />
                </li>
                <li>
                    <label>自我介绍</label>
                    <textarea id="F_Signature" name="F_Signature" class="form-control" style="height: 60px;"></textarea>
                </li>
                <li class="line">
                    <h5><span>联系方式</span></h5>
                </li>
                <li>
                    <label>手机号码</label>
                    <input id="F_MobilePhone" name="F_MobilePhone" type="text" class="form-control" />
                </li>
                <li>
                    <label>电子邮箱</label>
                    <input id="F_Email" name="F_Email" type="text" class="form-control" />
                </li>
                <li>
                    <label>微信号</label>
                    <input id="F_WeChat" name="F_WeChat" type="text" class="form-control" />
                </li>
            </ul>

        </div>

        <div id="b" class="tab-pane" style="padding: 15px;">

            <ul class="pop-list">
                <li>
                    <label>账户</label>
                    <input name="F_Account" type="text" class="form-control" />
                </li>
                @*<li>
            <label>密码</label>
            <input type="text" class="form-control" />
        </li>*@
                <li>
                    <label>第一次访问时间</label>
                    <input id="F_FirstVisitTime" name="F_FirstVisitTime" type="text" class="form-control" />
                </li>
                <li>
                    <label>上一次访问时间</label>
                    <input id="F_PreviousVisitTime" name="F_PreviousVisitTime" type="text" class="form-control" />
                </li>
                <li>
                    <label>最后修改密码时间</label>
                    <input id="F_ChangePasswordDate" name="F_ChangePasswordDate" type="text" class="form-control" />
                </li>
                <li>
                    <label>登录时间</label>
                    <input id="F_LastVisitTime" name="F_LastVisitTime" type="text" class="form-control" />
                </li>
                <li>
                    <label>登录次数</label>
                    <input id="F_LogOnCount" name="F_LogOnCount" type="text" class="form-control" />
                </li>
                <li>
                    <label>账户类型</label>
                    <input type="text" class="form-control" />
                </li>
                <li class="line">
                    <h5><span>修改密码</span></h5>
                </li>
                <li>
                    <label>旧密码</label>
                    <input id="oldPwd" type="password" class="form-control pwd" />
                </li>
                <li>
                    <label>新密码</label>
                    <input id="newPwd" type="password" class="form-control pwd" />
                </li>
                <li>
                    <label>确认新密码</label>
                    <input id="confirmPwd" type="password" class="form-control pwd" />
                </li>
                <li>
                    <div style="padding-left: 115px;">
                        <a id="" class="btn btn-primary" onclick="btn_changePassword()"><i class="fa fa-save" style="margin-right: 5px;"></i>确认修改</a>
                    </div>

                </li>

                <li class="line">
                    <h5><span>修改邮箱密码</span></h5>
                </li>               
                <li>
                    <label>密码</label>
                    <input id="F_EmailPassword" name="F_EmailPassword" type="password" class="form-control" />
                </li>
                <li>
                    <div style="padding-left: 115px;">
                        <a id="" class="btn btn-primary" onclick="btn_changeEmailPassword()"><i class="fa fa-save" style="margin-right: 5px;"></i>确认修改</a>
                    </div>

                </li>
            </ul>

        </div>
        <div id="c" class="tab-pane" style="padding-right: 15px;">
            <div class="zdyGirdPanel">
                <table id="gridList"></table>
                <div id="gridPager"></div>
            </div>

        </div>
        <div id="d" class="tab-pane" style="padding-right: 15px;">
            4
        </div>
    </div>
</div>


<script>
    //var keyValue = $.request("keyValue");

    $(function () {
        $.ajax({
            url: "/SystemManage/User/GetInfoJson",
            data: {},
            dataType: "json",
            async: false,
            success: function (data) {
                var $form1 = $("#a");
                $form1.formSerialize(data);
                $form1.find('.form-control, input').attr('readonly', 'readonly');

                var $form2 = $("#b");
                $form2.formSerialize(data);
                $form2.find('.form-control:not([type="password"])').attr('readonly', 'readonly');
                $('[name="F_Account"]', $form2).val($('#F_Account').val());
            }
        });

    });

    //修改密码
    function btn_changePassword() {
        if (!validatePwd()) {
            return;
        }

        $.post('/SystemManage/User/ChangePassword',
            {
                'oldPassword': $('#oldPwd').val(),
                'newPassword': $('#newPwd').val(),
                'confirmPassword': $('#confirmPwd').val()
            },
            function (result) {
                $('.pwd').val('');

                var data = JSON.parse(result);
                $.modalMsg(data.message);
            });
    }

    function btn_changeEmailPassword() {
        $.post('/SystemManage/User/ChangeEmailPassword',
            {
                'emailPwd': $('#F_EmailPassword').val()               
            },
            function (result) {
                //$('[type=password]').val('');

                var data = JSON.parse(result);
                $.modalMsg(data.message);
            });
    }

    //校验密码
    function validatePwd() {

        var oldPwdValue = $('#oldPwd').val();
        var newPwdValue = $('#newPwd').val();
        var confirmPwdValue = $('#confirmPwd').val();

        if (!validatePassword(oldPwdValue)) {
            return false;
        } else if (!validatePassword(newPwdValue)) {
            return false;
        } else if (!validatePassword(confirmPwdValue)) {
            return false;
        }

        return true;
    }

    //校验密码
    function validatePassword(pwdValue) {
        if (pwdValue == '' || pwdValue.length < 4 || pwdValue.length > 6) {
            $.modalMsg("密码的长度要求为 4~6 位");
            return false;
        }

        return true;
    }

    $(function () {
        initGridList();

        updateTableWidthFor100Percent($('#gbox_gridList'));
        updateTableWidthFor100Percent($('#gview_gridList'));
        updateTableWidthFor100Percent($('#gridList'));
        updateTableWidthFor100Percent($('#gridPager'));
        updateTableWidthFor100Percent($('.ui-jqgrid-htable'));
        updateTableWidthFor100Percent($('.ui-jqgrid-hdiv'));
        updateTableWidthFor100Percent($('.ui-jqgrid-bdiv'));
    });

    function updateTableWidthFor100Percent(element) {
        element.css('width', '100%');
    }


                //初始化列表
                function initGridList() {
                    var $gridList = $("#gridList");

                    $gridList.dataGrid({
                        url: "/SystemSecurity/Log/GetGridJson",
                        postData: { queryJson: JSON.stringify({
                            'keyword':'@OperatorProvider.Provider.GetCurrent().UserCode'
                        }) },
                        height: 630,
                        colModel: [
                            {
                                label: '时间', name: 'F_Date'
                            },
                            {
                                label: 'IP', name: 'F_IPAddress'
                            },
                            {
                                label: 'IP 地址', name: 'F_IPAddressName'
                            },
                            {
                                label: '类型', name: 'F_Type', formatter: function (cellvalue) {
                                    switch (cellvalue) {
                                        case 'Other':
                                            return '其他';
                                        case 'Login':
                                            return '登录';
                                        case 'Exit':
                                            return '退出';
                                        case 'Visit':
                                            return '访问';
                                        case 'Create':
                                            return '新增';
                                        case 'Delete':
                                            return '删除';
                                        case 'Update':
                                            return '修改';
                                        case 'Submit':
                                            return '提交';
                                        case 'Exception':
                                            return '异常';
                                        default:
                                            return '';
                                    }
                                    return '';
                                }
                            },
                            {
                                label: '模块', name: 'F_ModuleName'
                            },
                            {
                                label: '描述', name: 'F_Description'
                            }
                        ],
                        pager: "#gridPager",
                        viewrecords: true,
                        multiselect: false,
                        sortname: 'F_Date',
                        sortorder: 'desc',
                        ondblClickRow: function (rowid, iRow, iCol, e) {

                        }
                    });
                }

</script>
